/**
 * Created by Administrator on 2016/11/2.
 */
(function(){

    var invite={
        init:function(){
            this.area();
            this.areaTxt();
        },
        areaTxt:function(){ /*地区选择后显示地区*/
            var arr=window.location.search.split("&");
            for(var i= 0,iLen=arr.length;i<iLen;i++){
                var prv=/p_id/ig.test(arr[i]);
                var are=/c_id/ig.test(arr[i]);
                if(prv){

                    $(".select_area1 a").each(function(){
                        if($(this).data("areaid")==arr[i].split("=")[1]){
                            console.log($(this).text());
                            $(".select_area1 span").text($(this).text());
                        }
                    });
                }
                if(are){
                    $(".select_area2 a").each(function(){
                        if($(this).data("areaid")==arr[i].split("=")[1]){
                            $(".select_area2 span").text($(this).text());
                        }
                    });

                }
            }
        },
        area:function(){  /*地区选择*/
            this.areaShow();
        },
        areaShow:function(){

            $(".select_area2 p").hide();
            this.areaClick($(".select_area1"));
            this.areaClick($(".select_area2"));

            $(".select_area1").on("click","em",function(){
                $(this).parent().hide();
            });

            $(".select_area2").on("click","em",function(){
                $(this).closest(".select_list").hide();
            });

            $(document).on("click",function(){
                $(".select_area1").find(".select_list").hide();
                $(".select_area2").find(".select_list").hide();
            });
        },
        areaClick:function(obj){
            obj.on("click","span",function(event){
                $(this).parent().find(".select_list").toggle().end().siblings().find(".select_list").hide();
                event.stopPropagation();
            });
        },

    };

    invite.init();
})();


/*
 * banner切换
 * */

;(function($,window,document,undefined){
    var Init=function(opt){

        this.defaults={
            "$oWrap":null,
            "$PicList":null,
            "$prevBtn":null,
            "$nextBtn":null,
            "$smallBtnWrap":null,
            "delayTime":5000,
            "moveTime":1000,
            "smallBtnActive":"active"
        };
        this.settings=$.extend({},this.defaults,opt);
        this.str="";
        this.n=0;
        this.timer=null;
        this.iTrue=true;
        this.iLen=this.settings.$PicList.length;

    };
    Init.prototype={
        picChange:function(){
            this.addSmallBtn();
            this.setTime();
            this.smallBtnEvent();

        },
        smallBtnEvent:function(){
            var that=this;
            this.$smallBtn.each(function(index){

                $(this).on("click",function(){
                    that.n=index;
                    that.base();
                });
                that.clearTime($(this),that);
            });
        },
        setTime:function(){
            var that=this;
            this.timer=setInterval(function(){
                that.n++;
                if(that.n>that.iLen-1){
                    that.n=0;
                }
                that.base();
            },that.settings.delayTime);

        },
        clearTime:function(obj,wrap){
            obj.hover(function(){
                clearInterval(wrap.timer);
            },function(){
                wrap.setTime();
            });
        },
        addSmallBtn:function(){
            var That=this;
            this.settings.$PicList.each(function(index){
                $(this).css("z-index",10-index);
                That.str+='<a href="javascript:void(0);"><i></i></a>';
            });
            this.settings.$smallBtnWrap.append(this.str);
            this.$smallBtn=this.settings.$smallBtnWrap.find("a");
            this.$smallBtn.first().addClass(this.settings.smallBtnActive);
        },
        base:function(){
            var that=this;
            this.iTrue=false;
            this.$smallBtn.eq(this.n).addClass(this.settings.smallBtnActive).siblings().removeClass(this.settings.smallBtnActive);
            this.settings.$PicList.eq(this.n).css("display","block");
            this.settings.$PicList.eq(this.n).stop().animate({"opacity":1},this.settings.moveTime);
            var list=this.settings.$PicList.eq(this.n).siblings();
            this.settings.$PicList.eq(this.n).siblings().stop().animate({"opacity":0},this.settings.moveTime,function(){
                that.iTrue=true;
                list.css("display","none");
            });
        }
    };
    $.fn.PicChange=function(options){
        return new Init(options).picChange();
    }
})(jQuery,window,document);

/**banner切换*/
$(".invite_banner").PicChange({
    "$oWrap":$(".invite_banner"),
    "$PicList":$(".invite_banner").find("li"),
    "$smallBtnWrap":$(".h-smallBtn")
});
